<?php

namespace App\Http\Controllers\Api;

use App\Model\RoomShortcutMessages;
use Illuminate\Http\Request;

/**
 * 房间-快捷消息-管理
 */
class RoomShortcutMessagesController extends BaseController
{
    /**
     * @param Request $request
     */
    public function __construct(Request $request)
    {
        parent::__construct($request);
    }

    /**
     * 获取所有的文案
     * @return \Illuminate\Http\JsonResponse
     */
    public function index()
    {
        $data = RoomShortcutMessages::query()->orderBy('serial_number')->get()->toArray();
        return $this->toJson(self::SUCCESS, $data);
    }

    /**
     * 增加
     * @param Request $request
     * @return \Illuminate\Http\JsonResponse
     */
    public function add(Request $request)
    {
        $params = $request->input();
        $result = callKKAudioApi('room_shortcut_message/add', $params);
        if ($result['code'] == 0) {
            return $this->toJson(self::SUCCESS);
        }

        return $this->toJson(self::ERROR, [], $result['msg']);
    }

    /**
     * 删除
     * @param Request $request
     * @return \Illuminate\Http\JsonResponse
     */
    public function delete(Request $request)
    {
        $params = $request->input();
        $result = callKKAudioApi('room_shortcut_message/delete', $params);
        if ($result['code'] == 0) {
            return $this->toJson(self::SUCCESS);
        }

        return $this->toJson(self::ERROR, [], $result['msg']);
    }

    /**
     * 更新
     * @param Request $request
     * @return \Illuminate\Http\JsonResponse
     */
    public function update(Request $request)
    {
        $params = $request->input();
        $result = callKKAudioApi('room_shortcut_message/update', $params);
        if ($result['code'] == 0) {
            return $this->toJson(self::SUCCESS);
        }

        return $this->toJson(self::ERROR, [], $result['msg']);
    }
}
